package user

import (
	"wx-uniapp-go/internal/domain/errcode"
	"wx-uniapp-go/internal/logic/coupon_logic"
	"wx-uniapp-go/internal/repository/dto"
	"wx-uniapp-go/internal/server/echo"

	"github.com/gin-gonic/gin"
)

// GetUserCouponStat 获取用户优惠券统计
func GetUserCouponStat(c *gin.Context) {
	ctx := echo.TraceCtx(c)
	userId := c.GetInt64("user_id")

	req := new(dto.CouponUserStatReq)
	if err := c.ShouldBindQuery(req); err != nil {
		echo.Fail(c).Error(errcode.ParametersErr)
		return
	}

	req.UserId = userId

	resp, err := coupon_logic.NewCouponLogic(ctx).GetUserCouponStat(req)
	if err != nil {
		echo.Fail(c).Error(err)
		return
	}

	echo.Success(c, resp)
}

// GetRuleCouponStat 获取优惠券规则统计
func GetRuleCouponStat(c *gin.Context) {
	ctx := echo.TraceCtx(c)

	req := new(dto.CouponRuleStatReq)
	if err := c.ShouldBindQuery(req); err != nil {
		echo.Fail(c).Error(errcode.ParametersErr)
		return
	}

	resp, err := coupon_logic.NewCouponLogic(ctx).GetRuleCouponStat(req)
	if err != nil {
		echo.Fail(c).Error(err)
		return
	}

	echo.Success(c, resp)
}
